
import RdFeature from "../interface/RdFeature";


/**
 * 实现 数据和 txt的转换
 */

export default class RdTxt extends RdFeature{
    constructor(    ) {
        super();

    }


    static txtToRx(txt){
        let rx = new Rx();
        let buff=new TextEncoder().encode(txt);

        rx.loadData(buff);

        return rx;
    }


    rxToTxt(){
        let buff2 =this.outData()
        for(let i=buff2.length;i>1; i--){
            if(buff2[i-1]==0){
                buff2=  buff2 .subarray(0, i-1)
            }else {

                break
            }

        }

        let        res=new TextDecoder().decode(buff2);
        return res;


    }

}
